package com.uobgroup.ews.uam.core.domain;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;

import org.springframework.beans.factory.annotation.Configurable;

import com.uobgroup.ews.uam.core.enums.ScopeType;


@Configurable
@Entity
@NamedQueries({
   @NamedQuery(name = "ReferenceType.findReferenceTypesByScope", query = "SELECT R FROM ReferenceType R WHERE R.scope = :scope"),
   @NamedQuery(name = "ReferenceType.findReferenceTypeByIdAndScope", query = "SELECT R FROM ReferenceType R WHERE R.id = :id AND R.scope = :scope"),
   @NamedQuery(name = "ReferenceType.countReferenceTypesByScope", query = "SELECT COUNT(R) FROM ReferenceType R WHERE R.scope = :scope")})
public class ReferenceType extends BaseEntity {
   
   public static final String QUERY_FIND_REFERENCE_TYPE_BY_SCOPE = "ReferenceType.findReferenceTypesByScope";
   public static final String QUERY_COUNT_REFERENCE_TYPE_BY_SCOPE = "ReferenceType.countReferenceTypesByScope";
   public static final String QUERY_FIND_REFERENCE_TYPE_BY_ID_AND_SCOPE = "ReferenceType.findReferenceTypeByIdAndScope";
   
   public static final String PARAM_SCOPE = "scope";

   public static final String PARAM_NAME = "name";
   
   public static final String PARAM_ID = "id";
   
   @Id
   @GeneratedValue(strategy = GenerationType.AUTO)
   @Column(name = "id")
   private Long id;
   
   @NotNull
   @Size(max = 255)
   private String name;
   
   @NotNull
   @Size(max = 64)
   private String code;
   
   @Enumerated
   private ScopeType scope;
   
   @OneToMany(mappedBy="referenceType")
   private List<Reference> references = new ArrayList<Reference>();

   public Long getId() {
      return id;
   }

   public void setId(Long id) {
      this.id = id;
   }

   public String getName() {
      return name;
   }

   public void setName(String name) {
      this.name = name;
   }

   public String getCode() {
      return code;
   }

   public void setCode(String code) {
      this.code = code;
   }

   public ScopeType getScope() {
      return scope;
   }

   public void setScope(ScopeType scope) {
      this.scope = scope;
   }

   public List<Reference> getReferences() {
      return references;
   }

   public void setReferences(List<Reference> references) {
      this.references = references;
   }
}
